#ifndef GLWIDGET_H
#define GLWIDGET_H

#include <QGLWidget>
//#include <QVector>

class coord3D;
class vector3D;
class Robot;


enum objectEnums { CYLINDER = 0, PRISM, GRIPPER_OBJ, GRIPPER_OBJ1 };

#define PI = 3.14159265

class GLWidget : public QGLWidget
{
	Q_OBJECT

public:
	GLWidget(Robot *rbt, QWidget *parent = 0);
	~GLWidget();
	
	QSize minimumSizeHint() const;
	QSize sizeHint() const;
	void resetView();

public slots:
	void updateWidget();
	void robotLoaded();
        void rotateBy(int xAngle, int yAngle, int zAngle);
       


signals:
	int R1RotationChanged(int angle);
	int R2RotationChanged(int angle);
	int P1ExtensionChanged(int distance);
        void clicked();

protected:
	void initializeGL();
	void paintGL();
	void resizeGL(int width, int height);
	void mousePressEvent(QMouseEvent *event);
	void mouseMoveEvent(QMouseEvent *event);
        void mouseReleaseEvent(QMouseEvent *event);
        void wheelEvent(QWheelEvent *);
        void keyPressEvent(QKeyEvent *event);
//        void timerEvent(QTimerEvent *);


private:
	void makeObjects();
        void drawGrid(const int nSquares, const float size);
        void drawAxes(const float lenght);
	void drawRobotJoints();
	void drawRobotLinks();
        void drawTube(coord3D start, coord3D end);
	void makeCylinder(int cylinderSlices);
        void drawCylinder(coord3D center, vector3D orientation, bool axes);
	void makePrism();
        void drawPrism(coord3D center, vector3D orientation, bool axes);
	void makeGripper();
        void drawGripper(coord3D center, vector3D orientation, bool axes, bool clenched);

	void normalizeAngle(int *angle);
        void computeThirdPoint(float *point_X, float *point_Y, float x1, float x2, float y1, float y2);

	
	
	float cylinderRadius;
	
	Robot *robot;
	
	QPoint lastPos;
	
        int xRot;
        int yRot;
        int zRot;
//         int reset;
        float scale;
        float HorizontalMove;
        float VerticalMove;

	GLuint objects;
};

#endif
